{% extends "base.html" %}
{% load i18n plmapp_tags highlight %}

{# browse page #}

{% block css %}
{% endblock %}
{% block leftcolumn %} {% endblock %}

{% block content %}
    <div id="browser" class="tb-container-fluid">
        <div class="tb-row-fluid">
            {% block browse-left-panel %}
                <div id="type-panel" class="tb-span2">
                    {% block browse-type %}
                        <div>
                            <h3 class="hplm alternate" data-toggle="collapse" data-target="#br-types">
                                <span class="expander"></span>{% trans "Type" %} </h3>
                        </div>
                        <ul id="br-types" class="tb-collapse tb-in">
                            <li {% if type == "object"%}class="selected"{% endif %} >
                            <a href="/browse/object/{% add_get page='1' stype='' %}"><span>{% trans "Objects" %}</span></a>
                            </li>
                            <li {% if type == "part"%}class="selected"{% endif %} >
                            <a href="/browse/part/{% add_get page='1' stype='' %}"><span style="padding-left:1em;" >{% trans "Parts" %}</span></a>
                            </li>
                            <li {% if type == "topassembly"%}class="selected"{% endif %} >
                            <a href="/browse/topassembly/{% add_get page='1' stype='' %}"><span style="padding-left:2em;" >{% trans "Top assemblies" %}</span></a>
                            </li>
                            <li {% if type == "document"%}class="selected"{% endif %} >
                            <a href="/browse/document/{% add_get page='1' stype='' %}"><span style="padding-left:1em;" >{% trans "Documents" %}</span></a>
                            </li>
                            {% if not restricted %}
                                <li {% if type == "group"%}class="selected"{% endif %} >
                                <a href="/browse/group/{% add_get page='1' stype='' %}"><span>{% trans "Groups" %}</span></a></li>
                                <li {% if type == "user"%}class="selected"{% endif %} >
                                <a href="/browse/user/{% add_get page='1' stype='' %}"><span>{% trans "Users" %}</span></a>
                                </li>
                            {% endif %}
                            {% if request.user.is_authenticated %}
                                {% for etype in extra_types %}
                                    <li {% if type == etype%}class="selected"{% endif %} >
                                    <a href="/browse/{{etype.lower}}/{% add_get page='1' stype='' %}"><span>{{ etype }}</span></a>
                                    </li>
                                {% endfor %}
                            {% endif %}
                        </ul>
                    {% endblock %}

                    {% block browse-sort %}
                        <div>
                            <h3 class="hplm alternate" data-toggle="collapse" data-target="#br-sorts">
                                <span class="expander"></span> {% trans "Sort" %} </h3>
                        </div>
                        <ul id="br-sorts" class="tb-collapse tb-in">
                            <li {% if sort == "recently-added"%}class="selected"{% endif %} > 
                            <a href="{% add_get sort='recently-added' %}"><span>{% trans "Recently added" %}</span></a>
                            </li>
                            <li {% if sort == "name"%}class="selected"{% endif %} >
                            <a href="{% add_get sort='name' %}"><span>{% trans "Sorted by name" %}</span></a>
                            </li>
                            {% if type == "part" or type == "topassembly" %}
                                <li {% if sort == "children"%}class="selected"{% endif %} >
                                <a href="{% add_get sort='children' %}"><span>{% trans "Largest assemblies" %}</span></a>
                                </li>
                            {% endif %}
                            {% if type == "part" %}
                                <li {% if sort == "most-used"%}class="selected"{% endif %} >
                                <a href="{% add_get sort='most-used' %}"><span>{% trans "Most used" %}</span></a>
                                </li>
                            {% endif %}
                        </ul>
                    {% endblock %}
                    {% block browse-state %}
                        {% if plmobjects and not restricted %}
                            <div>
                                <h3 class="hplm alternate" data-toggle="collapse" data-target="#br-states"> 
                                    <span class="expander"></span>{% trans "State" %} </h3> 
                            </div>
                            <ul id="br-states" class="tb-collapse tb-in">
                                <li {% if state == "all"%}class="selected"{% endif %} >
                                <a href="{% add_get state='all' %}"><span>{% trans "All states" %}</span></a>
                                </li>
                                <li {% if state == "official"%}class="selected"{% endif %} >
                                <a href="{% add_get state='official' %}"><span>{% trans "Official state" %}</span></a>
                                </li>
                                <li {% if state == "published"%}class="selected"{% endif %} >
                                <a href="{% add_get state='published' %}"><span>{% trans "Published" %}</span></a>
                                <li>
                                {% if states %}
                                    <li data-toggle="collapse" data-target="#br-states-all" class="intermediate">
                                    <a><span>{% trans "Other states..." %}</span></a>
                                    <ul id="br-states-all" class="tb-collapse">
                                        {% for st in states %}
                                            <li {% if state == st %}class="selected"{% endif %} >
                                            <a href="{% add_get state=st %}"><span>{{ st }}</span></a>
                                            <li>
                                        {% endfor %}
                                    </ul>
                                    </li>
                                {% endif %}
                            </ul>
                        {% endif %}
                    {% endblock %}
                    {% block browse-subtypes %}
                        {% if subtypes and not restricted %}
                            <div>
                                <h3 class="hplm alternate collapsed" data-toggle="collapse" data-target="#br-subtypes"> 
                                    <span class="expander"></span>{% trans "Sub type" %} </h3>
                            </div>
                            <ul id="br-subtypes" class="tb-collapse">
                                {% for level, cls, cls_name in subtypes %}
                                    <li {% if stype == cls_name %}class="selected"{% endif %} > 
                                    <a href="{% add_get stype=cls_name %}"><span style="padding-left:{{ level }}em;">{{ cls_name }}</span></a>
                                    </li>
                                {% endfor %}
                            </ul>
                        {% endif %}
                    {% endblock %}
                    {% block browse-time %}
                         {% if not restricted %}
                             {% for time_filter in time_filters %}
                                 {% include "snippets/time_filter.html" %}
                                {% endfor %}
                        {% endif %}

                    {% endblock %}

                    {% if plmobjects and not restricted %}
                        <div>
                            <h3 class="hplm alternate collapsed" data-toggle="collapse" data-target="#br-templates"> 
                                <span class="expander"></span>{% trans "Templates" %} </h3> 
                        </div>
                        <ul id="br-templates" class="tb-collapse">
                            <li {% if template == "1"%}class="selected"{% endif %} >
                            <a href="{% add_get template='1' %}"><span>{% trans "Templates" %}</span></a>
                            </li>
                            <li {% if template != "1"%}class="selected"{% endif %} >
                            <a href="{% add_get template='0' %}"><span>{% trans "Any" %}</span></a>
                            </li>
                        </ul>
                    {% endif %}
                </div>
            {% endblock %}
            {% block browse-results %}
                <div id="browse-results" class="tb-span10">
                    <h3 class="hplm">{% trans "Results" %}</h3>
                    <div id="object_list">
                        <p id="results">
                        <span id="rtype">
                            {% if type == "object"%}
                                {% trans "Objects" %}.
                            {% elif type == "part" %}
                                {% trans "Parts" %}.
                            {% elif type == "topassembly" %}
                                {% trans "Top assemblies" %}.
                            {% elif type == "document" %}
                                {% trans "Documents" %}.
                            {% elif type == "user" %}
                                {% trans "User" %}.
                            {% elif type == "group" %}
                                {% trans "Group" %}.
                            {% else %}
                                {{ type }}.
                            {% endif %}
                            {% if stype and stype != "Object" and type != stype.lower %} {{ stype }}. {% endif %}
                        </span>

                        {% block sort-method %}
                            <span id="sort_method">
                                {% if sort == "name" %}
                                    {% trans "Sorted by name" %}.
                                {% elif type in "part topassembly" and sort == "children" %}
                                    {% trans "Largest assemblies" %}.
                                {% elif type == "part" and sort == "most-used" %}
                                    {% trans "Most used" %}.
                                {% else %}
                                    {% trans "Recently added" %}.
                                {% endif %}
                            </span>
                        {% endblock %}
                        {% block selected-state %}
                            {% if plmobjects %}
                                <span id="state_filter">
                                    {% if state == "official" %}
                                        {% trans "Only official objects" %}.
                                    {% elif state == "published" %}
                                        {% trans "Only published objects" %}.
                                    {% elif state == "all" %}
                                        {% trans "All objects"%}.
                                    {% else %}
                                        {{ state }}.
                                    {% endif %}
                                </span>
                            {% endif %}
                        {% endblock %}
                        {% block selected-time %}
                            {% if not restricted %}
                                 {% for time_filter in time_filters %}
                                     <span class="time_filter">{{time_filter.title|capfirst}}: {{ time_filter.display }}.</span>
                                 {% endfor %}
                            {% endif %}
                        {% endblock %}
                        <br/>
                        {% trans "Results" %}
                        <span id="numresults">
                            {% blocktrans with objects.start_index as start and objects.end_index as end and objects.paginator.count as total %}
                                ({{start}} - {{end}} on {{total}})
                            {% endblocktrans %}
                        </span> 
                        </p>
                        {% block browse-objects %}

                            {% with restricted|yesno:"public/," as suffix_url %}

                                {% for object in objects.object_list %}
                                    {% with object|main_type|add:"s/identity_card.html" as tpl %}
                                        {% include tpl %}
                                    {% endwith %}
                                {% endfor %}
                            {% endwith %}
                        {% endblock %}
                    </div>

                    {% show_pages_bar objects request %}
                </div>
            {% endblock %}
        </div>
    </div>
{% endblock %}
